capture log close

set more off
set matsize 10000

use rep_final, clear

	*noncitizens
	keep if cit==0

	
******************************************************************************
*Married last year

	*define control var
	local demog "age age2 male yreduc i.racegr"	
	local imm "ysm i.bpl " 
	local fe "i.statefip i.year "
	
	local full "`demog' `imm' `fe' "
	
	g post1=(year>=2013 & year<=2016)
	g post2=(year>=2017)
	
	g treatpost1=treatgr*post1
	g treatpost2=treatgr*post2
	
	foreach controlgr of varlist controlgrdaca  {
		foreach depvar of varlist marriedly  {
	
			
			display ""
			display "--------------------------------------"
			
			display "Dependent Variable: `depvar' "
			
			
			display "--------------------------------------"
		
	
			*post 2012 and post 2016; treatpost1 and treatpost2 both compare to pre-period
			
			reg `depvar' treatpost1 treatpost2 treatgr `fe'  if daca==1|`controlgr'==1 [pweight = perwt] , cluster(statefip)
			est sto e1
			
			reg `depvar' treatpost1 treatpost2 treatgr `demog' `fe'  if daca==1|`controlgr'==1   [pweight = perwt] , cluster(statefip)
			est sto e2

			reg `depvar' treatpost1 treatpost2 treatgr `full'  if daca==1|`controlgr'==1   [pweight = perwt] , cluster(statefip)
			est sto e3	

			
				*Make table 

			*using two treatment periods: post 2012 and post 2017
			esttab e1 e2 e3 ///
					using table1a.csv, se  ///
					title(Intermarriage Rate) ///
					b(%9.4f) se(%9.4f) star(* 0.1 ** 0.05 *** 0.01) ///
					nogaps replace		
			
				*dep var mean
	
			sum `depvar' [fweight=perwt] if e(sample) 
			}
			
		}

*********************************************************************************
*Married to a citizen last year, conditional on married last year.

	*married last year, currently still married with spouse present
	keep if marrinyr==2 & married==1 
	*spouse info is avail.
	drop if citizen_sp==.


* Define control variables 

	local demog "age age2 male yreduc i.racegr"
	local imm "ysm i.bpl " 
	local fe "i.statefip i.yrmarr "
	
	local full "`demog' `imm' `fe' "

	capture drop post1 post2 treatpost1 treatpost2
	g post1=(yrmarr>=2013 & yrmarr<=2016)
	g post2=(yrmarr>=2017)
	
	g treatpost1=treatgr*post1
	g treatpost2=treatgr*post2
	
	
	foreach controlgr of varlist controlgrdaca  {
		foreach depvar of varlist cit_sp {
	
			
			display ""
			display "--------------------------------------"
			
			display "Dependent Variable: `depvar' "
			
			
			display "--------------------------------------"
		
	
			*post 2012 and post 2016; treatpost1 and treatpost2 both compare to pre-period
			
			reg `depvar' treatpost1 treatpost2 treatgr `fe'  if daca==1|`controlgr'==1 [pweight = perwt] , cluster(statefip)
			est sto a1
			
			reg `depvar' treatpost1 treatpost2 treatgr `demog' `fe'  if daca==1|`controlgr'==1   [pweight = perwt] , cluster(statefip)
			est sto a2

			reg `depvar' treatpost1 treatpost2 treatgr `full'  if daca==1|`controlgr'==1   [pweight = perwt] , cluster(statefip)
			est sto a3	

			*Make table 

			*using two treatment periods
			esttab a1 a2 a3 ///
					using table1b.csv, se  ///
					title(Intermarriage Rate) ///
					b(%9.4f) se(%9.4f) star(* 0.1 ** 0.05 *** 0.01) ///
					nogaps replace		
		
			*dep var mean
			sum cit_sp [fweight=perwt] if e(sample) 
						
			}

	
			
		}



		
